<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改产品规格管理')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-partsattribute-edit" th:object="${zsyhPlatformPartsattribute}">
            <input name="id" th:field="*{id}" type="hidden">
            <input name="partsId" th:field="*{partsId}" type="hidden">
            <input id="attributeLogo" name="attributeLogo" th:field="*{attributeLogo}" class="form-control" type="hidden" required>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-3 control-label is-required">规格图：</label>
                        <div class="col-sm-8">
                            <p class="user-info-head" onclick="avatarLicense()"><img id="attributeLogoShow" class="img-thumbnail img-lg" th:src="*{attributeLogo}"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">规格名称：</label>
                        <div class="col-sm-8">
                            <input name="attributeName" th:field="*{attributeName}" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">补助金金额：</label>
                        <div class="col-sm-8">
                            <input name="attributePayPrice" th:field="*{attributePayPrice}" class="form-control" type="text">
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">合同价：</label>
                        <div class="col-sm-8">
                            <input name="attributeContractPrice" th:field="*{attributeContractPrice}" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">销售价：</label>
                        <div class="col-sm-8">
                            <input name="attributeSalePrice" th:field="*{attributeSalePrice}" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">补助金有效期（单位）：</label>
                        <div class="col-sm-8">
                            <input name="attributeWarranty" th:field="*{attributeWarranty}" class="form-control" type="text">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">二维码有效期（单位）：</label>
                        <div class="col-sm-8">
                            <input name="attributeInstall" th:field="*{attributeInstall}" class="form-control" type="text">
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">统一零售价：</label>
                        <div class="col-sm-8">
                            <input name="attributeRetailPrice" th:field="*{attributeRetailPrice}" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">统一批发价：</label>
                        <div class="col-sm-8">
                            <input name="attributeWholesalePrice" th:field="*{attributeWholesalePrice}" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
            </div>

            <!--<div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">订购最低数量：</label>
                        <div class="col-sm-8">
                            <input name="attributeQuantity" th:field="*{attributeQuantity}" class="form-control" type="text">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">最低批发价：</label>
                        <div class="col-sm-8">
                            <input name="attributeLowestPrice" th:field="*{attributeLowestPrice}" class="form-control" type="text">
                        </div>
                    </div>
                </div>
            </div>
-->
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">会长是否展示：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isShowProvice_' + dict.dictCode}" name="isShowProvice" th:value="${dict.dictValue}" th:field="*{isShowProvice}" required>
                                <label th:for="${'isShowProvice_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">配件店是否展示：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isShowCity_' + dict.dictCode}" name="isShowCity" th:value="${dict.dictValue}" th:field="*{isShowCity}" required>
                                <label th:for="${'isShowCity_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">维修师傅是否展示：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isShowWorker_' + dict.dictCode}" name="isShowWorker" th:value="${dict.dictValue}" th:field="*{isShowWorker}" required>
                                <label th:for="${'isShowWorker_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">是否包邮 ：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('zsyh_yesno')}">
                                <input type="radio" th:id="${'isPost_' + dict.dictCode}" name="isPost" th:value="${dict.dictValue}" th:field="*{isPost}" required>
                                <label th:for="${'isPost_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">备注(会长端)：</label>
                        <div class="col-sm-8">
                            <textarea name="attributeRemarks" class="form-control" required>[[*{attributeRemarks}]]</textarea>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">备注(店铺端)：</label>
                        <div class="col-sm-8">
                            <textarea name="attributeStoreRemarks" class="form-control" required>[[*{attributeStoreRemarks}]]</textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">产品品牌：</label>
                        <div class="col-sm-8">
                            <select name="attributeDistinguish" class="form-control m-b" th:with="type=${@dict.getType('parts_brand')}" required>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{attributeDistinguish}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">产品优势描述：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" th:field="*{attributeAdvantage}">
                    <div class="summernote" id="attributeAdvantage"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">产品使用说明书：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" th:field="*{attributeInstructions}">
                    <div class="summernote" id="attributeInstructions"></div>
                </div>
            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "zsyh/partsattribute";
        $("#form-partsattribute-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-partsattribute-edit').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/uploadOSS',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/uploadOSS",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });


        /*规格图片*/
        function avatarLicense() {
            var url = ctx + 'zsyh/partsattribute/avatarAttribute?attributeLogo='+$("#attributeLogo").val();
            layer.open({
                type: 2,
                area: [$(window).width()/2 + 'px', $(window).height() + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "上传门头图片",
                content: url,
                btn: ['确定', '关闭'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    debugger;
                    var iframeWin = layero.find('iframe')[0];
                    var imageUrl = layero.find('iframe')[0].contentWindow.$("#imageUrl").val();
                    iframeWin.contentWindow.submitHandler(index, layero);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

    </script>
</body>
</html>